package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "if_lading_bill")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class IfLadingBill extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, unique = true)
    private String code;

//    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, unique = true)
    private String billCode;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    @One(value = "loan", target = IfLoan.class, groups = {"IfLadingBill.search", "IfLadingBill.detail"},fieldset = {"id","code"} )
    private Long loanId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long contractId;

    /**
     * 质权人 （银行）
     */
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    @One(value = "pledgeeCompany", target = Company.class, fieldset = {"id","name"})
    private Long pledgee;

    /**
     * 出质人 （卖方）
     */
    @One(value = "pledgorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long pledgor;

    /**
     * 监管方 （仓储企业）
     */
    @One(value = "regulatorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long regulator;

    @DataField(value = IConstants.IF_LADING_BILL_DATA_TYPE.BILL_STATE, required = true, index = true)
    private String state = States.PENDING;

    @DataField(value = IConstants.IF_LADING_BILL_DATA_TYPE.BANK_ACK_STATE, required = true, index = true)
    private String bankAckState = BankAckStates.PENDING;

    @DataField(value = IConstants.IF_LADING_BILL_DATA_TYPE.STORAGE_ACK_STATE, required = true, index = true)
    private String storageAckState = StorageAckStates.PENDING;

    @One(value = "billApplyDocument", target = FileUpload.class, groups = {"IfLadingBill.search","IfLadingBill.detail"},fieldset = {"id","url","fileName"})
    private Long billApplyDoc;

    @One(value = "billConfirmDocument", target = FileUpload.class, groups = {"IfLadingBill.search","IfLadingBill.detail"},fieldset = {"id","url","fileName"})
    private Long billConfirmDoc;

    @One(value = "billReceiptDocument", target = FileUpload.class, groups = {"IfLadingBill.search","IfLadingBill.detail"},fieldset = {"id","url","fileName"})
    private Long billReceiptDoc;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getBillCode() {
        return billCode;
    }

    public void setBillCode(String billCode) {
        this.billCode = billCode;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getPledgee() {
        return pledgee;
    }

    public void setPledgee(Long pledgee) {
        this.pledgee = pledgee;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getBankAckState() {
        return bankAckState;
    }

    public void setBankAckState(String bankAckState) {
        this.bankAckState = bankAckState;
    }

    public String getStorageAckState() {
        return storageAckState;
    }

    public void setStorageAckState(String storageAckState) {
        this.storageAckState = storageAckState;
    }

    public Long getBillApplyDoc() {
        return billApplyDoc;
    }

    public void setBillApplyDoc(Long billApplyDoc) {
        this.billApplyDoc = billApplyDoc;
    }

    public Long getBillConfirmDoc() {
        return billConfirmDoc;
    }

    public void setBillConfirmDoc(Long billConfirmDoc) {
        this.billConfirmDoc = billConfirmDoc;
    }

    public Long getBillReceiptDoc() {
        return billReceiptDoc;
    }

    public void setBillReceiptDoc(Long billReceiptDoc) {
        this.billReceiptDoc = billReceiptDoc;
    }

    public Long getPledgor() {
        return pledgor;
    }

    public void setPledgor(Long pledgor) {
        this.pledgor = pledgor;
    }

    public Long getRegulator() {
        return regulator;
    }

    public void setRegulator(Long regulator) {
        this.regulator = regulator;
    }

    public interface States {
        String PENDING = "PENDING";
        String SUBMITTED = "SUBMITTED";
    }

    public interface BankAckStates {
        String PENDING = "PENDING"; //待确认
        String CONFIRMED = "CONFIRMED"; //已确认
    }

    public interface StorageAckStates {
        String PENDING = "PENDING"; //待确认
        String COMPLETED = "COMPLETED"; //完成
    }
}
